package com.ruoyi.app.controller;

import java.util.List;

import com.ruoyi.app.domain.HtCompareRecord;
import com.ruoyi.app.service.IHtCompareRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 对比记录Controller
 */
@RestController
@RequestMapping("/system/compare")
public class HtCompareRecordController extends BaseController {
    @Autowired
    private IHtCompareRecordService htCompareRecordService;

    /**
     * 查询对比记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:compare:list')")
    @GetMapping("/list")
    public TableDataInfo list(HtCompareRecord htCompareRecord) {
        startPage();
        List<HtCompareRecord> list = htCompareRecordService.selectHtCompareRecordList(htCompareRecord);
        return getDataTable(list);
    }

    /**
     * 获取对比记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:compare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(htCompareRecordService.selectHtCompareRecordById(id));
    }

    /**
     * 新增对比记录
     */
    @PreAuthorize("@ss.hasPermi('system:compare:add')")
    @Log(title = "对比记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HtCompareRecord htCompareRecord) {
        htCompareRecord.setCreateBy(SecurityUtils.getUsername());
        return toAjax(htCompareRecordService.insertHtCompareRecord(htCompareRecord));
    }

    /**
     * 修改对比记录
     */
    @PreAuthorize("@ss.hasPermi('system:compare:edit')")
    @Log(title = "对比记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HtCompareRecord htCompareRecord) {
        return toAjax(htCompareRecordService.updateHtCompareRecord(htCompareRecord));
    }

    /**
     * 删除对比记录
     */
    @PreAuthorize("@ss.hasPermi('system:compare:remove')")
    @Log(title = "对比记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(htCompareRecordService.deleteHtCompareRecordById(id));
    }
}
